package com.zhangyue.wqercs.patterndemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        int[] imgs = {
                R.mipmap.img_1,
                R.mipmap.img_2,
                R.mipmap.img_3,
                R.mipmap.img_4,
                R.mipmap.img_5,
                R.mipmap.img_6,
                R.mipmap.img_7,
                R.mipmap.img_8

        };
        List<ItemBean> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            ItemBean itemBean = new ItemBean("item:"+i,imgs[i]);
            list.add(itemBean);
        }
        RecyclerView recycler = findViewById(R.id.recycle);
        recycler.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        recycler.setAdapter(new MyAdapter(this,list));
    }
}
